# -*- coding: utf8 -*-

"""
	Ката Пакман : http://codingdojo.org/cgi-bin/wiki.pl?KataPacMan
"""

import unittest
import random

#	----------------------------------------------------------------------------

class FieldUnit:

	def __init__(self):

		self.X = 0
		self.Y = 0

	def SetX(self, x):

		self.X = x

	def SetY(self, y):

		self.Y = y

	def IsStepable(self):
		pass
		
	
#	----------------------------------------------------------------------------

class EOutOfScreen(Exception):

	def __init__(self):
		self.value = 'value'
	def __str__(self):
		return repr(self.value)

#	----------------------------------------------------------------------------

class WarField:
	
	def __init__(self):

		# Хранит все клетки поля
		self.field = []

		self.maxX = 0
		self.maxY = 0

	def SetMaxX(self, x):
		
		self.maxX = x

	def SetMaxY(self, y):

		self.maxY = y

	def AddFieldUnit(self, unit, x, y):

		if (x >= self.maxX) or (y >= self.maxY):
			raise EOutOfScreen

		unit.SetX(x)
		unit.SetY(y)
		self.field.append(unit)
#	----------------------------------------------------------------------------

class WallUnit(FieldUnit):

	def IsStepable(self):

		return False

#	----------------------------------------------------------------------------

class TestWallUnit(unittest.TestCase):

	def test_IsStepAble(self):

		unit = WallUnit()
		self.assertEqual(False, unit.IsStepable())


#	----------------------------------------------------------------------------

class TestWarField(unittest.TestCase):
	
	def test_SetX(self):
		
		field = WarField()
		field.SetMaxX(20)
		self.assertEqual(20, field.maxX)

	def test_SetY(self):

		field = WarField()
		field.SetMaxY(20)
		self.assertEqual(20, field.maxY)

	def test_AddFieldUnit(self):
		
		field = WarField()
		unit = FieldUnit()

		field.SetMaxX(20)
		field.SetMaxY(20)

		field.AddFieldUnit(unit, 8, 8)
		self.assertEqual(unit, field.field[0])

	
	def test_AddFieldUnitCoordinates(self):
		
		field = WarField()
		unit = FieldUnit()
		
		field.SetMaxX(20)
		field.SetMaxY(20)
		
		field.AddFieldUnit(unit, 8, 8)
		self.assertEqual(8, field.field[0].X)
		self.assertEqual(8, field.field[0].Y)

	def test_AddFieldUnitMax(self):
		
		field = WarField()
		unit = FieldUnit()
		
		field.SetMaxX(20)
		field.SetMaxY(20)

		self.assertRaises(EOutOfScreen, field.AddFieldUnit, unit, 30, 30)

	def test_AddFieldUnitMaxClose(self):
		
		field = WarField()
		unit = FieldUnit()
		
		field.SetMaxX(20)
		field.SetMaxY(20)

		self.assertRaises(EOutOfScreen, field.AddFieldUnit, unit, 20, 20)

#	----------------------------------------------------------------------------

class TestFieldUnit(unittest.TestCase):

	def test_SetX(self):

		unit = FieldUnit()
		unit.SetX(20)
		self.assertEqual(20, unit.X)

	def test_SetY(self):

		unit = FieldUnit()
		unit.SetY(20)
		self.assertEqual(20, unit.Y)

#	----------------------------------------------------------------------------

if __name__ == "__main__":

	unittest.main()
